package com.linq.cool.beauty.controller;

import com.linq.cool.beauty.domain.BeautyProductHistory;
import com.linq.cool.beauty.service.BeautyProductHistoryService;
import com.linq.cool.common.core.domain.BaseController;
import com.linq.cool.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: yqlin
 * @Date: 2021/2/9 01:48
 * @Description: 商品浏览历史
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("productHistory")
public class BeautyProductHistoryController extends BaseController {
    @Autowired
    private BeautyProductHistoryService beautyProductHistoryService;

    /**
     * 保存历史
     *
     * @param productHistory
     *
     * @return
     */
    @PostMapping("save")
    public Result<?> save(@RequestBody BeautyProductHistory productHistory) {
        beautyProductHistoryService.save(productHistory);
        return Result.ok("添加成功");
    }

    /**
     * 清空历史
     *
     * @return
     */
    @DeleteMapping("clearHistory")
    public Result<?> clearHistory() {
        beautyProductHistoryService.clearHistory();
        return Result.ok("清空成功");
    }

    /**
     * 分页查询
     *
     * @param current
     * @param size
     *
     * @return
     */
    @GetMapping("list/{current}/{size}")
    public Result<?> list(@PathVariable("current") long current, @PathVariable("size") long size) {
        return Result.ok(beautyProductHistoryService.listByPage(current, size));
    }

    /**
     * 根据id删除
     *
     * @param productHistoryId
     *
     * @return
     */
    @DeleteMapping("{productHistoryId}")
    public Result<?> remove(@PathVariable("productHistoryId") Long productHistoryId) {
        beautyProductHistoryService.removeById(productHistoryId);
        return Result.ok("删除成功");
    }
}
